package com.company.cloud.mall.modules.app.controller;

///**
// * 第三方支付通知
// */
//@Deprecated
//@Controller
//@RequestMapping("/shop/")
//@Api(tags="Shop_ 第三方支付通知")
public class OrderPayNotifyController {
	
//	private final static Logger LOGGER = LoggerFactory.getLogger(OrderPayNotifyController.class);
//	
//	@Autowired
//	private ShopOrderPayService shopOrderPayService;
//	@Autowired
//	private ShopAfterOrderPayService shopAfterOrderPayService;
	
//	@Autowired
//	private WxPayConfig wxPayConfig;
	
	
//	@RequestMapping(value = "/pay/wxjs",consumes = {"text/xml"},produces ="application/xml",method = RequestMethod.POST)
//	@ResponseBody
//	@SysLog("微信JSAPI支付结果通知")
//	@ApiOperation(value="微信JSAPI支付结果通知")
//	public String wxjsPayNotifyPay(@RequestBody String xmlBody) throws Exception {
//		System.out.println("*****************微信JSAPI支付结果通知*********************");
//		System.out.println(xmlBody);
//		try {
//			Map<String, String> returnMap= WXPay.getInstall(wxPayConfig).processResponseXml(xmlBody);
//			String resultcode= returnMap.get("result_code"); //业务结果  SUCCESS/FAIL
//			String err_code= returnMap.get("err_code"); //错误返回的信息描述
////			String err_code_des=returnMap.get("err_code_des"); //错误返回的信息描述
////			String total_fee=returnMap.get("total_fee"); //订单总金额，单位为分
//			String out_trade_no=returnMap.get("out_trade_no"); //商户系统内部订单号
////			String time_end=returnMap.get("time_end"); //支付完成时间，格式为yyyyMMddHHmmss
//			System.out.println("resultcode = " +resultcode);
//			
//			LoginUserInfo userInfo=new LoginUserInfo();
//			userInfo.setId(-3);
//			userInfo.setUserName("Third-Pay");
//			userInfo.setIp(IpUtils.getOpIp());
//			
//			PayResultReportParam params=new PayResultReportParam();
//			params.setSn(out_trade_no);
//			params.setState(PayResultModel.getWxMiniPayState(resultcode));
//			params.setMemo(resultcode);
//			params.setThirdState(resultcode);
//			params.setThirdMemo(err_code);
//			shopOrderPayService.payReport(params, PayConfirmChannel.ThirdCallback_Confirm, userInfo);
//		} catch (Exception e) {
//			LOGGER.debug("+++++:微信小程序回调错误;/pay/wxjs;回调内容:{}",xmlBody);
//			Map<String, String> data=new HashMap<String, String>();
//			data.put("return_code", WXPayConstants.FAIL);
//			data.put("return_msg", "process error");
//			return WXPayUtil.mapToXml(data);
//		}
//		
//		Map<String, String> data=new HashMap<String, String>();
//		data.put("return_code", WXPayConstants.SUCCESS);
//		data.put("return_msg", "OK");
//		return WXPayUtil.mapToXml(data);
//		return "";
//	}
	
	
//	@RequestMapping(value = "/refund/wxjs",consumes = {"text/xml"},produces ="application/xml",method = RequestMethod.POST)
//	@ResponseBody
//	@ApiOperation(value="微信JSAPI退款结果通知")
//	public String wxjsRefundNotifyPay(@RequestBody String xmlBody) throws Exception {
//		System.out.println("*****************微信JSAPI退款结果通知*********************");
//		System.out.println(xmlBody);
//		try {
//			Dict  dict= this.processRefundResponseXml(xmlBody);
//			String refundStatus= dict.getStr("refundStatus"); //退款状态 
//			String outRefundNo=dict.getStr("outRefundNo"); //商户系统内部退款单号
//			System.out.println(StrUtil.format("-----refundStatus={},outRefundNo={}", refundStatus,outRefundNo));
//			
//			LoginUserInfo userInfo=new LoginUserInfo();
//			userInfo.setId(-3);
//			userInfo.setUserName("Third-Pay");
//			userInfo.setIp(IpUtils.getOpIp());
//			shopAfterOrderPayService.callback(outRefundNo, refundStatus,userInfo);
//		} catch (Exception e) {
//			LOGGER.debug("222:微信小程序退款回调错误:{}",e.getMessage());
//			Map<String, String> data=new HashMap<String, String>();
//			data.put("return_code", WXPayConstants.FAIL);
//			data.put("return_msg", "process error");
//			return WXPayUtil.mapToXml(data);
//		}
//		Map<String, String> data=new HashMap<String, String>();
//		data.put("return_code", WXPayConstants.SUCCESS);
//		data.put("return_msg", "OK");
//		return WXPayUtil.mapToXml(data);
//		return "";
//	}
	
	
//    private Dict processRefundResponseXml(String xmlBody)throws Exception{
//    	Map<String, String> returnMap= WXPay.getInstall(wxPayConfig).processRefundResponseXml(xmlBody);
//		if(CollectionUtils.isEmpty(returnMap)) {
//			throw new Exception(String.format("XML To Map Error: %s"));
//		}
//		String refundStatus= returnMap.get("refund_status"); //退款状态 
//		String outRefundNo=returnMap.get("out_refund_no"); //商户系统内部退款单号
//		if(StringUtils.isEmpty(refundStatus)) {
//			  throw new Exception(String.format("No `refund_status` in XML: %s", xmlBody));
//		}
//		if(StringUtils.isEmpty(outRefundNo)) {
//			  throw new Exception(String.format("No `out_refund_no` in XML: %s", xmlBody));
//		}
//		return Dict.create().set("refundStatus", refundStatus).set("outRefundNo", outRefundNo);
//    	return null;
//    }
	
	
	
}
